<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>Aria: seekurPower.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Aria
   &#160;<span id="projectnumber">2.9.4</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('seekurPower_8cpp-example.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">seekurPower.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<p>Control Seekur or Seekur Jr. accessory power switching from command line options. Run with -help for help on command line options. See robot manuals and notes on <a href="http://robots.mobilerobots.com">http://robots.mobilerobots.com</a> for more information.</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;Aria.h&quot;</span></div><div class="line"></div><div class="line"><span class="keyword">typedef</span> <span class="keyword">struct </span>{</div><div class="line">  <span class="keyword">const</span> <span class="keywordtype">char</span> *option;</div><div class="line">  <span class="keywordtype">int</span> port;</div><div class="line">  <span class="keyword">const</span> <span class="keywordtype">char</span> *description;</div><div class="line">  <span class="keywordtype">int</span> <span class="keyword">set</span>;</div><div class="line">} powerspec;</div><div class="line"></div><div class="line">powerspec PowerSpecs[] = {</div><div class="line">  {<span class="stringliteral">&quot;pc2&quot;</span>, 1,  <span class="stringliteral">&quot;Turn onboard computer #2 on or off.&quot;</span>, 0},</div><div class="line">  {<span class="stringliteral">&quot;pc3&quot;</span>, 13,  <span class="stringliteral">&quot;Turn onboard computer #3 on or off.&quot;</span>, 0},</div><div class="line">  {<span class="stringliteral">&quot;pc4&quot;</span>, 14,  <span class="stringliteral">&quot;Turn onboard computer #4 on or off&quot;</span>, 0},</div><div class="line">  {<span class="stringliteral">&quot;pc5&quot;</span>, 15,  <span class="stringliteral">&quot;Turn onboard computer #5 on or off.&quot;</span>, 0},</div><div class="line">  {<span class="stringliteral">&quot;lrf1&quot;</span>, 9,  <span class="stringliteral">&quot;Turn laser rangefinder #1 on or off.&quot;</span>, 0},</div><div class="line">  {<span class="stringliteral">&quot;lrf2&quot;</span>, 24,  <span class="stringliteral">&quot;Turn laser rangefinder #2 on or off.&quot;</span>, 0},</div><div class="line">  {<span class="stringliteral">&quot;lrf1heat&quot;</span>, 11,  <span class="stringliteral">&quot;Turn laser rangefinder #1&#39;s heater on or off.&quot;</span>, 0},</div><div class="line">  {<span class="stringliteral">&quot;lrf2heat&quot;</span>, 27,  <span class="stringliteral">&quot;Turn laser rangefinder #2&#39;s heater on or off.&quot;</span>, 0},</div><div class="line">  {<span class="stringliteral">&quot;gps&quot;</span>, 6, <span class="stringliteral">&quot;Turn GPS receeiver on or off.&quot;</span>, 0},</div><div class="line">  {<span class="stringliteral">&quot;poe&quot;</span>, 4, <span class="stringliteral">&quot;Turn 12V Power over Ethernet port on or off.&quot;</span>, 0},</div><div class="line">  {<span class="stringliteral">&quot;lan&quot;</span>, 5, <span class="stringliteral">&quot;Turn internal LAN ethernet switch on or off.&quot;</span>, 0},</div><div class="line">  {<span class="stringliteral">&quot;camera-raw&quot;</span>, 12, <span class="stringliteral">&quot;Turn the 24V RVision camera on or off.&quot;</span>, 0},</div><div class="line">  {<span class="stringliteral">&quot;rvision-raw&quot;</span>, 12, <span class="stringliteral">&quot;Turn the 24V RVision camera on or off.&quot;</span>, 0},</div><div class="line">  {<span class="stringliteral">&quot;camera&quot;</span>, 10, <span class="stringliteral">&quot;Turn the 24V RVision camera on or off.&quot;</span>, 0},</div><div class="line">  {<span class="stringliteral">&quot;rvision&quot;</span>, 10, <span class="stringliteral">&quot;Turn the 24V RVision camera on or off.&quot;</span>, 0},</div><div class="line">  {<span class="stringliteral">&quot;ptu1&quot;</span>, 9, <span class="stringliteral">&quot;Turn pan/tilt unit #1 on or off.&quot;</span>, 0},</div><div class="line">  {<span class="stringliteral">&quot;ptu2&quot;</span>, 22, <span class="stringliteral">&quot;Turn pan/tilt unit #2 on or off.&quot;</span>, 0},</div><div class="line">  {<span class="stringliteral">&quot;ptu3&quot;</span>, 23, <span class="stringliteral">&quot;Turn pan/tilt unit #3 on or off.&quot;</span>, 0},</div><div class="line">  {<span class="stringliteral">&quot;arm&quot;</span>, 29, <span class="stringliteral">&quot;Turn the raw 24V manipulator arm drive power on or off.&quot;</span>, 0},</div><div class="line">  {<span class="stringliteral">&quot;armpower&quot;</span>, 29, <span class="stringliteral">&quot;Turn the raw 24V manipulator arm drive power on or off.&quot;</span>, 0},</div><div class="line">  {<span class="stringliteral">&quot;armlogic&quot;</span>, 8, <span class="stringliteral">&quot;Turn the regulated manipulator arm controller/logic power on or off.&quot;</span>, 0},</div><div class="line">  {<span class="stringliteral">&quot;armcam&quot;</span>, 7, <span class="stringliteral">&quot;Turn the arm camera or other 12V arm accessories on or off.&quot;</span>, 0}</div><div class="line">};</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)</div><div class="line">{</div><div class="line">  <span class="keywordtype">int</span> numPowerSpecs = <span class="keyword">sizeof</span>(PowerSpecs)/<span class="keyword">sizeof</span>(powerspec);</div><div class="line">  <a name="a0"></a><a class="code" href="classAria.html#ad99c16b5d947229d9f8e1c5b2d4cdd73">Aria::init</a>();</div><div class="line">  <a name="_a1"></a><a class="code" href="classArArgumentParser.html">ArArgumentParser</a> parser(&amp;argc, argv);</div><div class="line">  parser.<a name="a2"></a><a class="code" href="classArArgumentParser.html#a501694b62a7f8b0c3cadd84aeafe1b35">loadDefaultArguments</a>();</div><div class="line">  <a name="_a3"></a><a class="code" href="classArRobot.html">ArRobot</a> robot;</div><div class="line">  <a name="_a4"></a><a class="code" href="classArRobotConnector.html">ArRobotConnector</a> robotConnector(&amp;parser, &amp;robot);</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span>(!robotConnector.<a name="a5"></a><a class="code" href="classArRobotConnector.html#ab192ac393d9cc1e5b61b1a82b08d085d">connectRobot</a>())</div><div class="line">  {</div><div class="line">    <a name="a6"></a><a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a name="a7"></a><a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;seekurPower: Error: Could not connect to the robot.&quot;</span>);</div><div class="line">    <a name="a8"></a><a class="code" href="classAria.html#a10d71f3d4d0cf7f38c58a1f749f64a42">Aria::logOptions</a>();</div><div class="line">    <a name="a9"></a><a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(1);</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> (!<a name="a10"></a><a class="code" href="classAria.html#a1b090c01d88bb420b8cf8e0384d25ee1">Aria::parseArgs</a>() || parser.<a name="a11"></a><a class="code" href="classArArgumentParser.html#a08d0d87154763e4869f0342a47059886">checkArgument</a>(<span class="stringliteral">&quot;help&quot;</span>))</div><div class="line">  {</div><div class="line">    <a class="code" href="classAria.html#a10d71f3d4d0cf7f38c58a1f749f64a42">Aria::logOptions</a>();</div><div class="line">    <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;Options for seekurPower command (your robot may not have some of these devices):&quot;</span>);</div><div class="line">    <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;-&lt;n&gt; &lt;on|off|reset&gt;\t\tTurn port &lt;n&gt; on or off, or reset by turning off then on again. Refer to robot documentation or http://robots.mobilerobots.com/wiki/Seekur_Switched_Power_Outputs for list and notes.&quot;</span>);</div><div class="line">    <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0; i &lt; numPowerSpecs; ++i)</div><div class="line">      <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;-%s &lt;on|off|reset&gt;\t\t%s (port %d)&quot;</span>, PowerSpecs[i].option, PowerSpecs[i].description, PowerSpecs[i].port);</div><div class="line">    <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;-robotOff\t\tTurn whole robot off&quot;</span>);</div><div class="line">    <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(2);</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span>(parser.<a class="code" href="classArArgumentParser.html#a08d0d87154763e4869f0342a47059886">checkArgument</a>(<span class="stringliteral">&quot;-robotOff&quot;</span>))</div><div class="line">  {</div><div class="line">    <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;-robotOff given -- powering down entire robot with command #119 in 5 seconds...&quot;</span>);</div><div class="line">    <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 5; i &gt; 0; --i)</div><div class="line">    {</div><div class="line">      <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;Shutting down in %d seconds...&quot;</span>, i);</div><div class="line">      <a name="a12"></a><a class="code" href="group__easy.html#ga4dfb878a3f9123b8dd96ae05b2fd94cb">ArUtil::sleep</a>(1000);</div><div class="line">    }</div><div class="line">    robot.<a name="a13"></a><a class="code" href="classArRobot.html#a165e27bc81ed9f159820dfdf215d5500">com</a>(119);</div><div class="line">    <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(0);</div><div class="line">  }</div><div class="line">      </div><div class="line"></div><div class="line">  std::list&lt;powerspec&gt; todo;</div><div class="line"></div><div class="line">  <span class="keywordtype">int</span> nargs = parser.<a name="a14"></a><a class="code" href="classArArgumentParser.html#ad3221128461a8f3a84c78ec6e37ce82a">getArgc</a>();</div><div class="line">  <span class="keywordflow">for</span>(<span class="keywordtype">int</span> argi = 1; argi &lt; nargs; ++argi)</div><div class="line">  {</div><div class="line">    <span class="keyword">const</span> <span class="keywordtype">char</span> *opt = parser.<a name="a15"></a><a class="code" href="classArArgumentParser.html#a47aa47b8a59cdea0142a728db11ccbf9">getArg</a>(argi);</div><div class="line">    <span class="keywordflow">if</span>(opt[0] != <span class="charliteral">&#39;-&#39;</span>)</div><div class="line">    {</div><div class="line">      <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;seekurPower: Error: invalid option %s. Use -help for list of options.&quot;</span>, opt);</div><div class="line">      <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(4);</div><div class="line">    }</div><div class="line">    ++opt;</div><div class="line">    <span class="keywordflow">if</span>(opt[0] == <span class="charliteral">&#39;-&#39;</span>)</div><div class="line">      ++opt;</div><div class="line">    <span class="keywordtype">bool</span> found = <span class="keyword">false</span>;</div><div class="line">    <span class="keywordflow">if</span>(argi == nargs-1) <span class="comment">// option given as last argument, with no value</span></div><div class="line">    {</div><div class="line">      <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;seekurPower: Error: Missing argument to last option %s. Specify on, off or reset.&quot;</span>, opt);</div><div class="line">      <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(7);</div><div class="line">    }</div><div class="line">    <span class="keyword">const</span> <span class="keywordtype">char</span> *val = parser.<a class="code" href="classArArgumentParser.html#a47aa47b8a59cdea0142a728db11ccbf9">getArg</a>(++argi);</div><div class="line">    <span class="keywordflow">for</span>(<span class="keywordtype">int</span> pi = 0; pi &lt; numPowerSpecs; ++pi)</div><div class="line">    {</div><div class="line">      powerspec ps = PowerSpecs[pi];</div><div class="line">      <span class="keywordflow">if</span>(strcmp(opt, ps.option) == 0) </div><div class="line">      {</div><div class="line">        found = <span class="keyword">true</span>;</div><div class="line">        <span class="keywordflow">if</span>(strcmp(val, <span class="stringliteral">&quot;on&quot;</span>) == 0)</div><div class="line">          ps.set = 1;</div><div class="line">        <span class="keywordflow">else</span> <span class="keywordflow">if</span>(strcmp(val, <span class="stringliteral">&quot;off&quot;</span>) == 0)</div><div class="line">          ps.set = 0;</div><div class="line">        <span class="keywordflow">else</span> <span class="keywordflow">if</span>(strcmp(val, <span class="stringliteral">&quot;reset&quot;</span>) == 0)</div><div class="line">          ps.set = 2;</div><div class="line">        <span class="keywordflow">else</span></div><div class="line">        {</div><div class="line">          <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;seekurPower: Error: Invalid value &#39;%s&#39; for option %s. Use on, off or reset.&quot;</span>, val, opt);</div><div class="line">          <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(6);</div><div class="line">        }</div><div class="line">        todo.push_back(ps);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      }</div><div class="line">    }</div><div class="line">    <span class="keywordflow">if</span>(!found)</div><div class="line">    {</div><div class="line">      <span class="keywordflow">if</span>(<a name="a16"></a><a class="code" href="classArUtil.html#af78edf7d12d4e609d639ee774dc96929">ArUtil::isOnlyNumeric</a>(opt))</div><div class="line">      {</div><div class="line">        found = <span class="keyword">true</span>;</div><div class="line">        powerspec ps;</div><div class="line">        ps.option = opt;</div><div class="line">        ps.description = NULL;</div><div class="line">        ps.port = atoi(opt);</div><div class="line">        <span class="keywordflow">if</span>(strcmp(val, <span class="stringliteral">&quot;on&quot;</span>) == 0)</div><div class="line">          ps.set = 1;</div><div class="line">        <span class="keywordflow">else</span> <span class="keywordflow">if</span>(strcmp(val, <span class="stringliteral">&quot;off&quot;</span>) == 0)</div><div class="line">          ps.set = 0;</div><div class="line">        <span class="keywordflow">else</span> <span class="keywordflow">if</span>(strcmp(val, <span class="stringliteral">&quot;reset&quot;</span>) == 0)</div><div class="line">          ps.set = 2;</div><div class="line">        todo.push_back(ps);</div><div class="line">      }</div><div class="line">    }</div><div class="line">    <span class="keywordflow">if</span>(!found)</div><div class="line">    {</div><div class="line">      <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;seekurPower: Warning: unrecognized option %s. Use -help for list of options.&quot;</span>, opt);</div><div class="line">    }</div><div class="line">  }</div><div class="line"></div><div class="line"></div><div class="line">  <span class="keywordflow">for</span>(std::list&lt;powerspec&gt;::const_iterator i = todo.begin(); i != todo.end(); ++i)</div><div class="line">  {</div><div class="line">    powerspec ps = *i;</div><div class="line">    <span class="keywordflow">if</span>(ps.set == 2)</div><div class="line">    {</div><div class="line">      <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a name="a17"></a><a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;seekurPower: Switching %s (port %d) off, waiting 2 seconds., then switching it back on again...&quot;</span>, ps.option, ps.port);</div><div class="line">      robot.<a name="a18"></a><a class="code" href="classArRobot.html#a37991669749d064691406e575b00564d">com2Bytes</a>(116, ps.port, 0);</div><div class="line">      <a class="code" href="group__easy.html#ga4dfb878a3f9123b8dd96ae05b2fd94cb">ArUtil::sleep</a>(2000);</div><div class="line">      robot.<a class="code" href="classArRobot.html#a37991669749d064691406e575b00564d">com2Bytes</a>(116, ps.port, 1);</div><div class="line">    }</div><div class="line">    <span class="keywordflow">else</span></div><div class="line">    {</div><div class="line">      <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;seekurPower: Switching %s (port %d) %s...&quot;</span>, ps.option, ps.port, ps.set?<span class="stringliteral">&quot;on&quot;</span>:<span class="stringliteral">&quot;off&quot;</span>);</div><div class="line">      robot.<a class="code" href="classArRobot.html#a37991669749d064691406e575b00564d">com2Bytes</a>(116, ps.port, ps.set);</div><div class="line">    }</div><div class="line">  }</div><div class="line">  </div><div class="line"></div><div class="line">  <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(0);</div><div class="line">}</div><div class="line"></div></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
  </ul>
</div>
</body>
</html>
